package com.tengju.data.domain.model.activity;

import com.tengju.data.domain.shared.DomainException;
import com.tengju.data.domain.shared.DomainExceptionCode;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 大木
 * @date: 2021/10/13 5:38 下午
 */
@Getter
@AllArgsConstructor
public class ActivityDetail {

    ActivityId activityId;

    String activityName;

    LocalDate startTime;

    LocalDate endTime;

    public List<LocalDate> activityDays() {
        if (endTime.isBefore(startTime)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"活动时间错误");
        }
        long diff = endTime.toEpochDay() - startTime.toEpochDay();
        List<LocalDate> days = new ArrayList<>();
        days.add(startTime);
        for (int i = 1; i <= diff; i++) {
            days.add(startTime.plusDays(i));
        }
        return days;
    }

}
